import { Transaction } from '@app/models/transaction'

const Transactions = new class {
    async get(address: string, hash: string) {
        return await Transaction.findOne({address, hash})
    }

    async getByHash(hash: string) {
        return await Transaction.findOne({hash})
    }

    async insert(address: string, hash: string, tx: any) {
        const record = new Transaction()
        record.address = address
        record.hash = hash
        record.data = JSON.stringify(tx)
        return await record.save()
    }
}()

export { Transactions }
